# -*- coding: utf-8 -*-
from django.contrib import admin
from events.models import Event, Participant

"""
Event signup admin classes
"""

class SignupInline(admin.TabularInline):
    model = Participant
    can_delete = True
    exclude = Participant.recordOnlyFields()
    
class EventSignupAdmin(admin.ModelAdmin):
    change_form_template = 'events/signup_change_form.html'
    exclude = Event.recordOnlyFields()
    
    save_on_top = True
    inlines = [SignupInline]
    list_display = ('name', 'type', 'date', 'country', 'county', 'fieldName' )
    list_filter = ('date', 'type', 'country', 'county', 'fieldName')
    
class EventSignupData(Event):
    """
    proxy the Event model sharing the same instance to apply different admin logic
    """
    class Meta:
        proxy = True

admin.site.register(EventSignupData, EventSignupAdmin)        

"""
Event records admin classes
"""
        
class RecordInline(admin.TabularInline):
    model = Participant
    can_delete = True
    exclude = Participant.signupOnlyFields()
    template='events/records_tabular.html'
        
class EventRecordAdmin(admin.ModelAdmin):
    change_form_template = 'events/record_change_form.html'
    exclude = Event.signupOnlyFields()
    save_on_top = True
    inlines = [RecordInline]
    list_display = ('name', 'date', 'type','country', 'county', 'fieldName')
    list_filter = ('date', 'type', 'country', 'county', 'fieldName')
#     recordReadOnly = ('name', 'date', 'type','country', 'county', 'field')
#     
#     def get_readonly_fields(self, request, obj=None):
#         return self.recordReadOnly + self.readonly_fields

class EventRecordData(Event):
    """
    proxy the Event model sharing the same instance to apply different admin logic
    """
    class Meta:
        proxy = True
        
admin.site.register(EventRecordData, EventRecordAdmin)


class ExportInlines(admin.TabularInline):
    model = Participant
    
class EventDataExportAdmin(admin.ModelAdmin):
    change_form_template = 'events/export_form.html'
    inlines = [ExportInlines]
    list_display = ('name', 'date', 'type','country', 'county', 'fieldName')
    list_filter = ('date', 'type', 'country', 'county', 'fieldName')
    
class EventExportData(Event):
    class Meta:
        proxy = True

admin.site.register(EventExportData, EventDataExportAdmin)   